home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-25 | 31.1 KB | 1,094 lines | [TEXT/MPS ] |
- {[d-,h-,k+,o=100,q+,r+,rec+,t=2,u+,:+,j=15/20/25/30/35/40/45/50/57/1$]} {Pasmat opts!}
-
- {$S Window}
-
- UNIT SVEditWindow;
- (*
- Version 3.0d8
-
- Copyright © SRL Data 1992, 1993
-
- All rights reserved
-
- Produced by : SRL Data
- Originally Developed for UK.DTS
- *)
-
- {The window and text handling routines for the SVEdit example program}
-
- {
- New for 3.0d2
-
- 19-Feb-92 : NH : Implement PrintWindow
- Change PageStarts to PageEnds
- Fix out by one in GetPageEnds
-
- 26-Feb-92 : NH : Put in final printing implementation
- : Fix inThumb scrolling
- : Put in kTextOffset to replace kTextMargin for better borders
-
- 28-Feb-92 : NH : gCurrSection zapped - Incoming AppleEvents make keeping track
- via a global very messy. Now check to see when in a section as
- required.
-
- New for 3.0d3
-
- 07-Apr-92 : NH : PrPicFile added to PrintWindow.
-
- 3-Jun-92 : NH : Fixed bug in DrawPageBreaks (kTextOffset added twice)
- Put in progress dialog for printing.
-
- 7-Jun-92 : NH : Fixed bug in PrintWindow - pageBounds was a pointer,
- never initialised so randomly trashed memory when calced
- pageBounds for printing
-
- oldMax,oldValue,theResult - dead vars - removed
- New for 3.0d5
-
- 21-Aug-92 : NH : Added isForNewDoc to NewDocument.
- Also count of new windows for Untitled #
- Eversaved implemented instead of name = untitled
- }
-
- INTERFACE
-
- USES MemTypes, QuickDraw, OSIntf, ToolIntf, Traps, Editions, Printing, SVEditGlobals, SVEditUtils,
-
- SVEditions, SVAppleEvents;
-
- FUNCTION DPtrFromWindowPtr(w: WindowPtr): DPtr;
-
- PROCEDURE MyGrowWindow(w: WindowPtr;
- p: Point);
-
- PROCEDURE DoZoom(w: WindowPtr;
- c: INTEGER;
- p: Point);
-
- PROCEDURE DoContent(theWindow: WindowPtr;
- theEvent: EventRecord);
-
- PROCEDURE DoActivate(theWindow: WindowPtr;
- activate : BOOLEAN);
-
- PROCEDURE DoUpdate(theDoc: DPtr);
-
- FUNCTION NewDocument(isForOldDoc:Boolean): DPtr;
-
- PROCEDURE CloseMyWindow(aWindow: WindowPtr);
-
- PROCEDURE ShowSelect(theDoc: DPtr);
-
- PROCEDURE AdjustScrollbars(theDoc: DPtr;
- needsResize: BOOLEAN);
-
- PROCEDURE GetWinContentRect(theWindow:WindowPtr; VAR r:Rect);
-
- PROCEDURE ResizeWindow(theDoc: DPtr);
-
- PROCEDURE ResizePageSetupForDocument(theDoc: DPtr);
-
- PROCEDURE InvalidateDocument(theDoc: DPtr);
-
- PROCEDURE DrawPageExtras(theDoc:DPtr);
-
- PROCEDURE PrintWindow(theDoc:DPtr; askUser:BOOLEAN);
-
- IMPLEMENTATION
-
- USES Packages;
-
- CONST
- kControlInvisible = 0;
- kControlVisible = $FF;
- kScrollbarWidth = 16;
- kScrollbarAdjust = kScrollbarWidth - 1;
- kScrollTweek = 2;
- kTextOffset = 5;
- kButtonScroll = 10;
-
- kMaxPages = 1000; (* Assumes pages > 32 pixels high *)
-
- kHOffset = 20; (* Stagger window offsets *)
- kVOffset = 20;
-
- kTBarHeight = 20;
- kMBarHeight = 20;
-
- TYPE
- PageEndsArray = ARRAY [1..kMaxPages] OF INTEGER;
- PPageEnds = ^PageEndsArray;
- HPageEnds = ^PPageEnds;
-
- {$S Window}
-
- FUNCTION DPtrFromWindowPtr(w: WindowPtr): DPtr;
-
- BEGIN
- IF w = NIL THEN
- DPtrFromWindowPtr := NIL
- ELSE
- DPtrFromWindowPtr := DPtr(GetWRefCon(w));
- END;
-
- {$S main}
-
- PROCEDURE AdjustTE(theDoc: DPtr);
-
- { Scroll the TERec around to match up to the potentially updated scrollbar
- values. This is really useful when the window resizes such that the
- scrollbars become inactive and the TERec had been previously scrolled. }
-
- VAR
- h : INTEGER;
- v : INTEGER;
-
- BEGIN
- h := (theDoc^.theText^^.viewRect.left - theDoc^.theText^^.destRect.left) -
- GetCtlValue(theDoc^.hScrollBar) + kTextOffset;
-
- v := (theDoc^.theText^^.viewRect.top -
- theDoc^.theText^^.destRect.top) - GetCtlValue(theDoc^.vScrollBar) + kTextOffset;
-
- IF (h<>0) OR (v<>0) THEN
- BEGIN
- TEScroll(h, v, theDoc^.theText);
- DrawPageExtras(theDoc);
- END;
- END; { AdjustTE }
-
- {$S Main}
-
- PROCEDURE AdjustHV(isVert : BOOLEAN;
- control : ControlHandle;
- theDoc : DPtr;
- canRedraw: BOOLEAN);
-
- {Calculate the new control maximum value and current value, whether it is the horizontal or
- vertical scrollbar. The vertical max is calculated by comparing the number of lines to the
- vertical size of the viewRect. The horizontal max is calculated by comparing the maximum document
- width to the width of the viewRect. The current values are set by comparing the offset between
- the view and destination rects. If necessary and we canRedraw, have the control be re-drawn by
- calling ShowControl.}
-
- {TEStyleSample-vertical max originally used line by line calculations-lineheight was a
- constant value so it was easy to figure out what the range should be and pin the value
- within range. Now we need to use max and min values in pixels rather than in nlines}
-
- VAR
- docTE : TEHandle;
- value : INTEGER;
- max : INTEGER;
- oldValue : INTEGER;
- oldMax : INTEGER;
- sizeRect : Rect;
-
- BEGIN { AdjustHV }
- sizeRect := theDoc^.pageSize;
- docTE := theDoc^.theText;
- oldValue := GetCtlValue(control);
- oldMax := GetCtlMax(control);
- IF isVert THEN
- BEGIN
- { new for TEStyleSample }
- max := (TEGetHeight(docTE^^.nLines, 0, docTE)) - (docTE^^.viewRect.bottom -
- docTE^^.viewRect.top);
-
- END
- ELSE
- max := sizeRect.right - (docTE^^.viewRect.right - docTE^^.viewRect.left);
-
- max := max + kTextOffset + kTextOffset; (* Allow over scroll by kTextOffset *)
-
- IF max < 0 THEN
- max := 0; { check for negative values }
- SetCtlMax(control, max);
- IF isVert THEN
- value := docTE^^.viewRect.top - docTE^^.destRect.top
- ELSE
- value := docTE^^.viewRect.left - docTE^^.destRect.left;
-
- value := value + kTextOffset;
-
- IF value < 0 THEN
- value := 0
- ELSE
- IF value > max THEN
- value := max; { pin the value to within range }
-
- SetCtlValue(control, value);
- IF canRedraw & ((max <> oldMax) | (value <> oldValue)) THEN
- ShowControl(control); { check to see if the control can be re-drawn }
- END; { AdjustHV }
-
- {$S Main}
-
- PROCEDURE AdjustScrollValues(theDoc : DPtr;
- canRedraw: BOOLEAN);
-
- { Simply call the common adjust routine for the vertical and horizontal scrollbars. }
-
- BEGIN { AdjustScrollValues }
- AdjustHV(TRUE, theDoc^.vScrollBar, theDoc, canRedraw);
- AdjustHV(FALSE, theDoc^.hScrollBar, theDoc, canRedraw);
- END; { AdjustScrollValues }
-
- PROCEDURE GetTERect(window: WindowPtr;
- VAR teRect: Rect);
-
- { return a rectangle that is inset from the portRect by the size of
- the scrollbars and a little extra margin. }
-
- BEGIN { GetTERect }
- teRect := window^.portRect;
- teRect.bottom := teRect.bottom - kScrollbarAdjust; { and for the scrollbars }
- teRect.right := teRect.right - kScrollbarAdjust;
- END; { GetTERect }
-
- PROCEDURE AdjustScrollSizes(theDoc: DPtr);
-
- { Re-calculate the position and size of the viewRect and the scrollbars.
- kScrollTweek compensates for off-by-one requirements of the scrollbars
- to have borders coincide with the growbox. }
-
- VAR
- teRect : Rect;
-
- BEGIN { AdjustScrollSizes }
- GetTERect(theDoc^.theWindow, teRect); {start with teRect}
- WITH theDoc^.theWindow^.portRect DO
- BEGIN
- theDoc^.theText^^.viewRect := teRect;
-
- MoveControl(theDoc^.vScrollBar, right - kScrollbarAdjust, - 1);
- SizeControl(theDoc^.vScrollBar, kScrollbarWidth, (bottom - top) - (kScrollbarAdjust -
- kScrollTweek));
- MoveControl(theDoc^.hScrollBar, - 1, bottom - kScrollbarAdjust);
- SizeControl(theDoc^.hScrollBar, (right - left) - (kScrollbarAdjust - kScrollTweek),
- kScrollbarWidth);
- END; { with }
- END; { AdjustScrollSizes }
-
- {$S Window}
-
- PROCEDURE AdjustScrollbars(theDoc: DPtr;
- needsResize: BOOLEAN);
-
- { Turn off the controls by jamming a zero into their contrlVis fields
- (HideControl erases them and we don't want that). If the controls are to
- be resized as well, call the procedure to do that, then call the procedure
- to adjust the maximum and current values. Finally reset the controls
- to be visible if not in background. }
-
- BEGIN { AdjustScrollbars }
- WITH theDoc^ DO
- BEGIN
-
- vScrollBar^^.contrlVis := kControlInvisible; { turn them off }
- hScrollBar^^.contrlVis := kControlInvisible;
-
- IF needsResize THEN { move and size if needed }
- AdjustScrollSizes(theDoc);
-
- AdjustScrollValues(theDoc, NOT needsResize); { fool with max and current value }
-
- { Now, restore visibility in case we never had to ShowControl during adjustment }
-
- IF NOT gInBackground THEN
- BEGIN
- vScrollBar^^.contrlVis := kControlVisible; { turn them on }
- hScrollBar^^.contrlVis := kControlVisible;
- END
- ELSE
- BEGIN (* make sure they stay invisible *)
- IF (vScrollBar^^.contrlVis <> 0) THEN
- HideControl(vScrollBar);
- IF (hScrollBar^^.contrlVis <> 0) THEN
- HideControl(hScrollBar);
- END;
- END;
- END; { AdjustScrollbars }
-
- {$S Window}
-
- PROCEDURE GetWinContentRect(theWindow:WindowPtr; VAR r:Rect);
- BEGIN
- r := theWindow^.portRect;
- r.right := r.right - kScrollBarAdjust;
- r.bottom := r.bottom - kScrollBarAdjust;
- END; (* GetWinContentRect *)
-
- {$S Window}
-
- PROCEDURE InvalidateDocument(theDoc: DPtr);
- VAR oldPort : GrafPtr;
-
- BEGIN
- GetPort(oldPort);
- SetPort(theDoc^.theWindow);
- InvalRect(theDoc^.theWindow^.portRect);
- SetPort(oldPort);
- END;
-
- PROCEDURE ResizeWindow(theDoc: DPtr);
-
- { Called when the window has been resized to fix up the controls and content }
-
- BEGIN { ResizeWindow }
- AdjustScrollbars(theDoc, TRUE);
- AdjustTE(theDoc);
- InvalidateDocument(theDoc);
- END; { ResizeWindow }
-
- PROCEDURE ResizePageSetupForDocument(theDoc: DPtr);
-
- { Called when the window has been resized to fix up the controls and content }
-
- BEGIN { ResizePageSetupForDocument }
- theDoc^.pageSize := theDoc^.thePrintSetup^^.prInfo.rPage;
- OffsetRect(theDoc^.pageSize, -theDoc^.pageSize.left, -theDoc^.pageSize.top);
-
- theDoc^.theText^^.destRect.right := theDoc^.theText^^.destRect.left + theDoc^.pageSize.right;
-
- TECalText(theDoc^.theText);
-
- ResizeWindow(theDoc);
- END; { ResizePageSetupForDocument }
-
- {$S Main}
-
- PROCEDURE CommonAction(control: ControlHandle;
- VAR amount: INTEGER);
-
- { Common algorithm for setting the new value of a control. It returns the actual amount
- the value of the control changed. Note the pinning is done for the sake of returning
- the amount the control value changed. }
-
- VAR
- value : INTEGER;
- max : INTEGER;
-
- BEGIN { CommonAction }
- value := GetCtlValue(control); { get current value }
- max := GetCtlMax(control); { and max value }
- amount := value - amount;
- IF amount < 0 THEN
- amount := 0
- ELSE
- IF amount > max THEN
- amount := max;
- SetCtlValue(control, amount);
- amount := value - amount; { calculate true change }
- END; { CommonAction }
-
- {$S Main}
-
- PROCEDURE VActionProc(control: ControlHandle;
- part: INTEGER);
-
- { Determines how much to change the value of the vertical scrollbar by and how
- much to scroll the TE record. }
-
- VAR
- amount : INTEGER;
- window : WindowPtr;
- theDoc : DPtr;
-
- BEGIN { VActionProc }
- IF part <> 0 THEN
- BEGIN
- window := control^^.contrlOwner;
- theDoc := DPtrFromWindowPtr(window);
- CASE part OF
- inUpButton, inDownButton: amount := 24;
- inPageUp, inPageDown:
- amount := theDoc^.theText^^.viewRect.bottom - theDoc^.theText^^.viewRect.top; { one
- page }
- END; { case }
- IF (part = inDownButton) OR (part = inPageDown) THEN
- amount := - amount; { reverse direction }
- CommonAction(control, amount);
-
- IF amount <> 0 THEN
- BEGIN
- TEScroll(0, amount, theDoc^.theText);
- DrawPageExtras(theDoc);
- END;
- END; { if }
- END; { VActionProc }
-
- {$S Main}
-
- PROCEDURE HActionProc(control: ControlHandle;
- part: INTEGER);
-
- { Determines how much to change the value of the horizontal scrollbar by and how
- much to scroll the TE record. }
-
- VAR
- amount : INTEGER;
- window : WindowPtr;
- theDoc : DPtr;
-
- BEGIN { HActionProc }
- IF part <> 0 THEN
- BEGIN
- window := control^^.contrlOwner;
- theDoc := DPtrFromWindowPtr(window);
- CASE part OF
- inUpButton, inDownButton: amount := kButtonScroll; { a few pixels }
- inPageUp, inPageDown:
- amount := theDoc^.theText^^.viewRect.right - theDoc^.theText^^.viewRect.left; { a
- page }
- END; { case }
- IF (part = inDownButton) OR (part = inPageDown) THEN
- amount := - amount; { reverse direction }
- CommonAction(control, amount);
- IF amount <> 0 THEN
- BEGIN
- TEScroll(amount, 0, theDoc^.theText);
- DrawPageExtras(theDoc);
- END;
- END; { if }
- END; { HActionProc }
-
- {*-----------------------------------------------------------------------
- Name: ShowSelect
- Purpose: Scrolls the text selection into view.
- -----------------------------------------------------------------------*}
-
- {$S Window}
-
- PROCEDURE ShowSelect(theDoc: DPtr);
-
- BEGIN
- AdjustScrollbars(theDoc, FALSE);
-
- (*
- Let TextEdit do the hard work of keeping the selection visible…
- *)
-
- TEAutoView(TRUE, theDoc^.theText);
- TESelView(theDoc^.theText);
- TEAutoView(FALSE, theDoc^.theText);
-
- (*
- Now rematch the text and the scrollbars…
- *)
-
- SetCtlValue(theDoc^.hScrollBar,
- theDoc^.theText^^.viewRect.left - theDoc^.theText^^.destRect.left + kTextOffset);
-
- SetCtlValue(theDoc^.vScrollBar,
- theDoc^.theText^^.viewRect.top - theDoc^.theText^^.destRect.top + kTextOffset);
-
- END; (* ShowSelect *)
-
- {$S Window}
-
- PROCEDURE OffsetWindow(aWindow: WindowPtr);
-
- VAR
- theWidth, theHeight, theHScreen, theVScreen: INTEGER;
- xWidth, xHeight, hMax, vMax, wLeft, wTop: INTEGER;
-
- BEGIN
-
- theWidth := aWindow^.portRect.right - aWindow^.portRect.left;
- theHeight := aWindow^.portRect.bottom - aWindow^.portRect.top + kTBarHeight;
-
- theHScreen := screenBits.bounds.right - screenBits.bounds.left;
- theVScreen := screenBits.bounds.bottom - screenBits.bounds.top;
-
- xWidth := theHScreen - theWidth;
- xHeight := theVScreen - (theHeight + kMBarHeight);
-
- hMax := (xWidth DIV kVOffset) + 1;
- vMax := (xHeight DIV KVOffset) + 1;
-
- gWCount := gWCount + 1;
-
- wLeft := (gWCount MOD hMax) * kVOffset;
- wTop := ((gWCount MOD vMax) * KVOffset) + kTBarHeight + kMBarHeight;
-
- MoveWindow(aWindow, wLeft, wTop, FALSE);
- END;
-
- PROCEDURE GetLocalUpdateRgn(window: WindowPtr;
- localRgn: RgnHandle);
-
- { Returns the update region in local coordinates }
-
- BEGIN { GetLocalUpdateRgn }
- CopyRgn(WindowPeek(window)^.updateRgn, localRgn); { save old update region }
- WITH window^.portBits.bounds DO
- OffsetRgn(localRgn, left, top); { convert to local coords }
- END; { GetLocalUpdateRgn }
-
- {$S Window}
-
- PROCEDURE MyGrowWindow(w: WindowPtr;
- p: Point);
-
- VAR
- savePort : GrafPtr;
- theResult : Longint;
- r : Rect;
-
- BEGIN
- GetPort(savePort);
- SetPort(w);
- SetRect(r, 80, 80, screenBits.bounds.right, screenBits.bounds.bottom);
- theResult := GrowWindow(w, p, r);
- IF (theResult <> 0) THEN
- IssueSizeWindow(w, LoWord(theResult), HiWord(theResult));
-
- SetPort(savePort);
- END;
-
- {$S Window}
-
- PROCEDURE DoZoom(w: WindowPtr;
- c: INTEGER;
- p: Point);
-
- VAR
- savePort : GrafPtr;
-
- BEGIN
- GetPort(savePort);
- SetPort(w);
- IF TrackBox(w, p, c) THEN
- BEGIN
- EraseRect(w^.portRect);
- IssueZoomCommand(w, c);
- END;
- END;
-
- {$S Window}
-
- PROCEDURE DoContent(theWindow: WindowPtr;
- theEvent: EventRecord);
-
- VAR
- cntlCode : INTEGER;
- part : INTEGER;
- theControl : ControlHandle;
- savePort : GrafPtr;
- extend : BOOLEAN;
- theDoc : DPtr;
- value : INTEGER;
-
- BEGIN
- GetPort(savePort);
- SetPort(theWindow);
- theDoc := DPtrFromWindowPtr(theWindow);
-
- GlobalToLocal(theEvent.where);
- cntlCode := FindControl(theEvent.where, theWindow, theControl);
- IF (cntlCode = 0) THEN
- BEGIN
- {only extend the selection if the shiftkey is down}
- extend := (BitAnd(theEvent.modifiers, ShiftKey) <> 0);
-
- IF ptInRect(theEvent.where, theDoc^.theText^^.viewRect) THEN
- TEClick(theEvent.where, extend, theDoc^.theText);
- END
- ELSE
- IF cntlCode = inThumb THEN
- BEGIN
- value := GetCtlValue(theControl);
- part := TrackControl(theControl, theEvent.where, NIL);
- IF (part <> 0) THEN
- BEGIN
- value := value - GetCtlValue(theControl);
- IF value <> 0 THEN
- BEGIN
- IF theControl = theDoc^.vScrollBar THEN
- TEScroll(0, value, theDoc^.theText)
- ELSE
- TEScroll(value, 0, theDoc^.theText);
- DrawPageExtras(theDoc);
- END;
- END; { if }
- END
- ELSE
- IF theControl = theDoc^.vScrollBar THEN
- part := TrackControl(theControl, theEvent.where, @VActionProc)
- ELSE
- part := TrackControl(theControl, theEvent.where, @HActionProc);
-
- SetPort(savePort);
-
- END;
-
- (*$S Window*)
- PROCEDURE DoActivate(theWindow: WindowPtr;
- activate : BOOLEAN);
-
- VAR
- err : OSErr;
- r : Rect;
- theDoc : DPtr;
-
- BEGIN
- IF (theWindow <> NIL) THEN
- BEGIN
- theDoc := DPtrFromWindowPtr(theWindow);
- SetPort(theWindow);
- DrawGrowIcon(theWindow);
- GetWinContentRect(theWindow, r);
- InvalRect(r);
- IF activate THEN
- BEGIN
- TEActivate(theDoc^.theText);
- ShowControl(theDoc^.vscrollBar);
- ShowControl(theDoc^.hscrollBar);
- DisableItem(myMenus[editM], undoCommand);
- err := TEFromScrap;
- IF (gWCount = 0) THEN
- SetShortMenus;
- END
- ELSE
- BEGIN
- TEDeactivate(theDoc^.theText);
- HideControl(theDoc^.vscrollBar);
- HideControl(theDoc^.hscrollBar);
- err := ZeroScrap;
- err := TEToScrap;
- END;
- END;
- END;
-
- {$S Window}
- PROCEDURE GetPageEnds(pageHeight: INTEGER;
- theText : TEHandle;
- pageBounds: PPageEnds;
- VAR nPages: INTEGER);
-
- VAR pageBase : INTEGER; (* total pixel offset of pages so far *)
- thisLine : INTEGER;
- lastLine : INTEGER;
- thisPage : INTEGER; (* Current page being calced *)
- pageSoFar : INTEGER; (* Page height used so far by lines on this page *)
- thisLineH : INTEGER; (* Height of text line *)
- pageFirstLine : INTEGER; (* Line # of top of page *)
-
- BEGIN
- pageBase := 0;
- thisLine := 1;
- lastLine := theText^^.nLines;
-
- thisPage := 1;
- pageSoFar := 0;
- WHILE (thisLine <= lastLine) OR (pageSoFar<>0) DO
- BEGIN
- pageFirstLine := thisLine;
- thisLineH := TEGetHeight(thisLine, thisLine, theText);
-
- WHILE (thisLineH+pageSoFar< pageHeight) AND
- (thisLine <= lastLine) DO
- BEGIN
- pageSoFar := pageSoFar + thisLineH;
- thisLine := thisLine +1;
- thisLineH := TEGetHeight(thisLine, thisLine, theText);
- END;
-
- IF (pageSoFar<>0) THEN
- BEGIN
- pageBounds^[thisPage] := pageSoFar+pageBase;
- pageBase := pageBounds^[thisPage];
- thisPage := thisPage + 1;
- pageSoFar:= 0;
- END;
-
- (*
- Special case text line taller than page
- *)
-
- IF (thisLine = pageFirstLine) AND
- (thisLineH > pageHeight) THEN
- BEGIN
- REPEAT
- pageBounds^[thisPage] := pageBase+pageHeight;
- pageBase := pageBounds^[thisPage];
- thisPage := thisPage + 1;
- thisLineH := thisLineH - pageHeight;
- UNTIL (thisLineH < pageHeight);
- pageSoFar := thisLineH; (* Carry bottom of large line to next page *)
- thisLine := thisLine + 1; (* carry xs on as pageSoFar and start measuring next line *)
- END;
- END;
-
- nPages := thisPage -1;
-
- END; (* GetPageEnds *)
-
- PROCEDURE DrawPageBreaks(theDoc : DPtr);
- VAR PageEnds : PageEndsArray;
- nPages : INTEGER;
- ctr : INTEGER;
- lineBase : INTEGER;
- viewRect : Rect;
- pageHeight : INTEGER;
-
- BEGIN
- pageHeight := theDoc^.pageSize.bottom - theDoc^.pageSize.top;
-
- GetPageEnds(pageHeight,
- theDoc^.theText,
- @pageEnds,
- nPages);
-
- lineBase := theDoc^.theText^^.destRect.top;
- viewRect := theDoc^.theText^^.viewRect;
-
- PenPat(gray);
- FOR ctr := 1 to nPages-1 DO
- BEGIN
- MoveTo(viewRect.left, lineBase+PageEnds[ctr]);
- LineTo(viewRect.right,lineBase+PageEnds[ctr]);
- END;
- PenNormal;
- END; (* DrawPageBreaks *)
-
- PROCEDURE DrawPageExtras(theDoc:DPtr);
- VAR oldPort : GrafPtr;
- oldClip : RgnHandle;
- rectToClip : Rect;
-
- BEGIN
- GetPort(oldPort);
- SetPort(theDoc^.theWindow);
-
- oldClip := NewRgn;
- GetClip(oldClip);
-
- GetWinContentRect(theDoc^.theWindow,rectToClip);
- ClipRect(rectToClip);
-
- { draw the borders }
-
- IF theDoc^.showBorders THEN
- ShowSectionBorders(theDoc);
-
- { and then the page breaks }
-
- DrawPageBreaks(theDoc);
-
- SetClip(oldClip);
-
- DisposeRgn(oldClip);
-
- SetPort(oldPort);
- END; (* DrawPageExtras *)
-
- PROCEDURE DoUpdate(theDoc: DPtr);
-
- VAR
- aWindow : WindowPtr;
- savePort : GrafPtr;
- rectClip : Rect;
-
- BEGIN
- aWindow := theDoc^.theWindow;
- GetPort(savePort);
- SetPort(aWindow);
- BeginUpdate(aWindow);
-
- ClipRect(aWindow^.portRect);
- EraseRect(aWindow^.portRect);
- DrawControls(aWindow);
- DrawGrowIcon(aWindow);
-
- GetWinContentRect(aWindow, rectClip);
- ClipRect(rectClip);
-
- TEUpdate(aWindow^.portRect, theDoc^.theText);
-
- DrawPageExtras(theDoc);
-
- EndUpdate(aWindow);
- ClipRect(aWindow^.portRect);
-
- SetPort(savePort);
- END; (* DoUpdate *)
-
- {$S Window}
-
- FUNCTION NewDocument(isForOldDoc:Boolean): DPtr;
- VAR
- destRect : Rect;
- viewRect : Rect;
- vScrollRect : Rect;
- hScrollRect : Rect;
- myDoc : DPtr;
- myWindow : WindowPtr;
- vScroll : ControlHandle;
- hScroll : ControlHandle;
- theName : Str255;
- newNumber : Str255;
-
- BEGIN
- IF (gWCount = 0) THEN
- SetLongMenus;
-
- myDoc := NIL;
- myWindow := GetNewWindow(windowID, NIL, Pointer( - 1));
- IF (myWindow <> NIL) THEN
- BEGIN
- IF (NOT isForOldDoc) THEN
- BEGIN
- GetWTitle(myWindow, theName);
- gNewDocCount := gNewDocCount+1;
- NumToString(gNewDocCount, newNumber);
- IF (gNewDocCount>1) THEN
- BEGIN
- theName := CONCAT(theName,' #');
- theName := CONCAT(theName, newNumber);
- SetWTitle(myWindow, theName);
- END;
- END;
-
- OffsetWindow(myWindow);
-
- SetPort(myWindow);
-
- myDoc := DPtr(NewPtr(sizeOf(DocRec)));
-
- SetWRefCon(myWindow, ord4(myDoc));
-
- myDoc^.theWindow := myWindow;
-
- vScrollRect := myWindow^.portRect;
-
- vScrollRect.left := vScrollRect.right - kScrollBarAdjust;
- vScrollRect.right := vScrollRect.left + kScrollBarWidth;
-
- vScrollRect.bottom := vScrollRect.bottom - 14;
- vScrollRect.top := vScrollRect.top - 1;
-
- vScroll := NewControl(myWindow, vScrollRect, '', TRUE, 0, 0, 0, scrollBarProc, 0);
-
- hScrollRect := myWindow^.portRect;
- hScrollRect.top := hScrollRect.bottom - kScrollBarAdjust;
- hScrollRect.bottom := hScrollRect.top + kScrollBarWidth;
-
- hScrollRect.right := hScrollRect.right - 14;
- hScrollRect.left := hScrollRect.left - 1;
- hScroll := NewControl(myWindow, hScrollRect, '', TRUE, 0, 0, 0, scrollBarProc, 0);
-
- myDoc^.vScrollBar := vScroll;
- myDoc^.hScrollBar := hScroll;
- myDoc^.lastID := 0;
-
- myDoc^.firstSection := NIL;
- myDoc^.lastSection := NIL;
- myDoc^.numSections := 0;
-
- myDoc^.dirty := FALSE;
-
- GetTERect(myWindow, viewRect);
- destRect := viewRect;
-
- myDoc^.theFont := Times;
- myDoc^.theStyle := [];
- myDoc^.theSize := 12;
-
- myDoc^.thePrintSetup := THPrint(NewHandle(SizeOf(TPrint)));
-
- PrOpen;
- PrintDefault(myDoc^.thePrintSetup);
- PrClose;
-
- myDoc^.pageSize := myDoc^.thePrintSetup^^.prInfo.rPage;
- OffsetRect(myDoc^.pageSize, -myDoc^.pageSize.left, -myDoc^.pageSize.top);
-
- destRect.right := destRect.left + myDoc^.pageSize.right;
-
- OffsetRect(destRect, kTextOffset, kTextOffset);
-
- TextFont(Times);
- TextSize(12);
- TextFace([]);
-
- myDoc^.theText := TEStylNew(destRect, viewRect);
-
- {
- SetClikLoop(@AutoScroll, myDoc^.theText);
- }
-
- myDoc^.theFileName := '';
- myDoc^.everSaved := FALSE;
- myDoc^.theWindow := myWindow;
-
- myDoc^.showBorders := FALSE;
-
- ResizeWindow(myDoc);
- END;
- NewDocument := myDoc;
- END;
-
- {$S Window}
-
- PROCEDURE CloseMyWindow(aWindow: WindowPtr);
-
- VAR
- aDocument : DPtr;
- theText : TEHandle;
-
- BEGIN
- HideWindow(aWindow);
- aDocument := DPtrFromWindowPtr(aWindow);
-
- theText := aDocument^.theText;
- TEDispose(theText);
-
- IF (aDocument^.thePrintSetup<>NIL) THEN
- DisposHandle(Handle(aDocument^.thePrintSetup));
-
- DisposPtr(Ptr(aDocument));
- DisposeWindow(aWindow);
-
- gWCount := gWCount - 1;
-
- {if there are no more windows open, set up the short menus}
- IF gWCount = 0 THEN
- SetShortMenus;
-
- END;
-
- (*
- Name : PrintWindow
- Function : Prints the document supplied in theDoc. askUser controls interaction
- with the user.
-
- Uses extra memory equal to the size of the textedit use in the
- printed document.
- *)
-
- PROCEDURE PrintWindow(theDoc:DPtr; askUser:BOOLEAN);
- VAR oldPort : GrafPtr;
- printerTE : TEHandle;
- printerPort : TPPrPort;
- printView : Rect;
- printerTextStyles : StScrpHandle;
- pageBounds : PageEndsArray;
- nPages : INTEGER;
- oldSelStart : INTEGER;
- oldSelEnd : INTEGER;
- pageCtr : INTEGER;
- abort : BOOLEAN;
- rectToClip : Rect;
- thePrinterStatus : TPrStatus;
- progressDialog : DialogPtr;
-
- BEGIN
- abort := FALSE;
-
- (*
- Preserve the current port
- *)
- GetPort(oldPort);
- PrOpen;
-
-
- IF askUser THEN
- abort := NOT PrJobDialog(theDoc^.thePrintSetup);
-
- IF abort THEN
- BEGIN
- PrClose;
- Exit(PrintWindow);
- END;
-
- progressDialog := GetNewDialog(1005, NIL, POINTER(-1));
-
- DrawDialog(progressDialog);
-
- printerPort := PrOpenDoc(theDoc^.thePrintSetup, NIL, NIL);
- SetPort(GrafPtr(printerPort));
-
- (*
- Put the window text into the printer port
- *)
-
- printView := theDoc^.thePrintSetup^^.prInfo.rPage;
- printerTE := TEStylNew(printView, printView);
-
- oldSelStart := theDoc^.theText^^.selStart;
- oldSelEnd := theDoc^.theText^^.selEnd;
-
- TESetSelect(0,theDoc^.theText^^.teLength, theDoc^.theText);
-
- printerTextStyles := GetStylScrap(theDoc^.theText);
-
- TESetSelect(oldSelStart, oldSelEnd, theDoc^.theText);
-
- HLock(Handle(theDoc^.theText^^.hText));
-
- TEStylInsert( Ptr(theDoc^.theText^^.hText^),
- theDoc^.theText^^.teLength,
- printerTextStyles,
- printerTE);
-
- HUnLock(Handle(theDoc^.theText^^.hText));
-
- (*
- Work out the offsets
- *)
- printerTE^^.destRect := printView; (* GetPageEnds calls TECalText *)
-
- GetPageEnds(printView.bottom-printView.top,
- printerTE,
- @pageBounds,
- nPages);
-
- TEDeactivate(printerTE);
-
- FOR pageCtr := 1 to nPages DO
- IF NOT abort THEN
- BEGIN
- PrOpenPage(printerPort, NIL);
-
- rectToClip := printView;
-
- IF (pageCtr > 1) THEN
- rectToClip.bottom := rectToClip.top + (pageBounds[pageCtr]-pageBounds[pageCtr-1])
- ELSE
- rectToClip.bottom := rectToClip.top + pageBounds[pageCtr];
-
- ClipRect(rectToClip);
-
- IF (PrError = iPrAbort) THEN
- abort := TRUE;
-
- IF not abort THEN
- TEUpdate(printView, printerTE);
-
- IF (PrError = iPrAbort) THEN
- abort := TRUE;
-
- PrClosePage(printerPort);
-
- TEScroll(0,rectToClip.top-rectToClip.bottom, printerTE);
- END;
-
- TEDispose(printerTE);
-
- PrCloseDoc(printerPort);
-
- IF ( theDoc^.thePrintSetup^^.prJob.bJDocLoop = bSpoolLoop ) AND
- ( PrError = noErr ) AND
- (NOT abort) THEN
- PrPicFile( theDoc^.thePrintSetup, NIL, NIL, NIL, thePrinterStatus);
-
- PrClose;
-
- DisposDialog(progressDialog);
-
- SetPort(oldPort);
- InvalRect(oldPort^.portRect);
- END;
- END.
-